package com.itheima.ThreadPrac5;

import java.util.ArrayList;
import java.util.Collections;

public class MyThread extends Thread{

    ArrayList<Integer> list=new ArrayList<>();

    public MyThread(ArrayList<Integer> list) {
        this.list = list;
    }

    @Override
    public void run() {

        while (true)
        {
            synchronized (MyThread.class)
            {
                if(list.size()==0)
                {
                    break;
                }
                else
                {
                    Collections.shuffle(list);
                    Integer prize = list.remove(0);
                    System.out.println(getName()+"又产生了一个"+prize+"元大奖");
                }
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
